<template>
  <div class="zh-platform-user">
    <nav-header></nav-header>
    <div class="zh-table">
      <div class="zh-table-open clear">
        <div class="zh-open-left fl">
          <div class="open-width" style="width: 160px" v-if="!$store.state.platformInformation">
            <el-cascader placeholder="请选择组织架构" :options="orgDatas" :props="orgDataProps" v-model="selectedOrgOptions">
            </el-cascader>
          </div>
          <div class="open-width" style="width: 130px">
            <el-select v-model="roles_id" filterable placeholder="请选择角色">
              <el-option v-for="item in roleData" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </div>

          <!-- <div class="open-width" style="width: 145px" v-if="showTeacherAbout">
                        v-if="只有教师才出现"
                            <el-select v-model="subject_id" filterable placeholder="请选择科目">
                                <el-option
                                    v-for="item in subjectData"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                    </div> -->
          <div class="open-width">
            <el-input v-model="keyword" placeholder="用户名称 帐号" @keyup.enter.native="searchFunc"></el-input>
          </div>
          <el-button type="primary" @click="searchFunc">搜索</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </div>
        <div class="zh-open-right fr">
          <el-button type="primary" @click="jumpAdd">添加用户</el-button>
          <el-button type="primary" @click="batchImport">批量导入</el-button>
          <el-button type="primary" @click="exportUser">导出Excel表</el-button>
          <el-button type="danger" @click="deleteMuiltUser_confirm">批量删除</el-button>
        </div>
      </div>
      <div class="zh-table-contents" v-loading="loading.status" :element-loading-text="loading.txt">
        <el-table :data="listData" @selection-change="tableSelectionChange" border max-height="600" style="width: 100%">
          <el-table-column type="selection" width="50" align="center" :selectable="checkSelectable" fixed>
          </el-table-column>
          <el-table-column prop="start_num" label="序号" align="center" show-overflow-tooltip width="50">
          </el-table-column>
          <el-table-column prop="number" label="账号" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="rename" label="组织" v-if="$store.state.checkLevel" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="name" label="用户名" align="center" show-overflow-tooltip>
            <!-- <template slot-scope="scope">
                            {{scope.row.name}}
                            只有教师才显示
                            <span class="home-color" v-if="showTeacherAbout && parseInt(scope.row.is_famous)=== 1">已推首页</span>
                        </template> -->
          </el-table-column>
          <el-table-column prop="role_name" label="角色" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="sex_name" label="性别" align="center" show-overflow-tooltip width="60">
          </el-table-column>
          <!-- <el-table-column
                        prop="sub_name"
                        label="任职科目"
                        align="center"
                        v-if="false"
                        show-overflow-tooltip
                        >
                        v-if="只有教师才出现"
                    </el-table-column> -->
          <!-- <el-table-column
                        prop="create_time"
                        label="注册时间"
                        v-if="user_multistage === false"
                        align="center"
                        show-overflow-tooltip
                        >
                    </el-table-column> -->
          <el-table-column prop="login_time" label="最后登录" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="login_count" label="登录次数" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="face_path" label="人脸照片" align="center" show-overflow-tooltip>
            <template slot-scope="scope">
              <img v-if="scope.row.face_path" :src="BASE_URL + scope.row.face_path" @click="openViewImg(scope.row)"
                style="width: 28px;height: 35px;">
            </template>
          </el-table-column>
          <!-- <el-table-column
                        prop="login_count"
                        v-if="user_multistage === false"
                        label="状态"
                        align="center"
                        show-overflow-tooltip
                        >
                        <template slot-scope="scope">
                            <span v-if="scope.row.status === 1">正常</span>
                            <span v-if="scope.row.status === 2">未通过</span>
                            <span v-if="scope.row.status === 3">禁用中</span>
                        </template>
                    </el-table-column> -->
          <el-table-column label="操作" align="center" :width="showTeacherAbout === true ? '200' : '170'">
            <template slot-scope="scope" v-if="scope.row.check_power === true">
              <el-button @click="detailsVisible(scope.row)" type="text">详情</el-button>
              <el-button @click="jumpEdit(scope.row.id)" type="text">编辑</el-button>
              <el-button @click="changeUser_confirm(scope.row, 1)" v-if="parseInt(scope.row.status) === 3"
                type="text">启用</el-button>
              <el-button @click="changeUser_confirm(scope.row, 3)" v-if="parseInt(scope.row.status) === 1"
                type="text">禁用</el-button>

              <!-- v-if="推首页只有教师才出现" -->
              <!-- <template v-if="showTeacherAbout">
                                <el-button @click="pushTeacherIndex_confirm( scope.row, 0 )" v-if="parseInt(scope.row.is_famous)=== 1" type="text" >退首页</el-button>
                                <el-button @click="pushTeacherIndex_confirm( scope.row, 1 )" v-else type="text" >推首页</el-button>
                            </template> -->

              <el-button @click="deleteUser_confirm(scope.row)" type="text" class="delete-button">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <div class="table-pagination" v-show="total_number > 10">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="userParam.page" :page-sizes="[10, 20, 30, 40, 50, 100]" :page-size="userParam.pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="total_number">
          </el-pagination>
          <div class="pagination-button">
            <el-button @click="getList" type="primary" icon="el-icon-refresh" circle title="刷新数据" size="mini">
            </el-button>
          </div>
        </div>
      </div>
    </div>
    <!-- 用户详情 -->
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" title="用户信息" :visible.sync="isDetails"
      class="details-content" width="40%">
      <div class="card" v-for="(item, index) in detailData" :key="index">
        <p>{{ item.name }}</p>
        <div>
          <el-row v-for="(val, indx1) in item.contents" :key="indx1">
            <template v-if="val.title == '登录帐号'">
              <el-col :span="5">
                <div class="grid-content bg-purple">{{ val.title }}：</div>
              </el-col>
              <el-col :span="19">
                <div class="grid-content bg-purple-light" v-html="val.content ? val.content : '-'"></div>
              </el-col>
            </template>
            <template v-else>
              <el-col :span="5">
                <div class="grid-content bg-purple">{{ val.title }}：</div>
              </el-col>
              <el-col :span="19">
                <div v-if="val.title == '人脸照片'">
                  <img v-if="val.content" style="width:100px ;height: 140px;" :src="BASE_URL + val.content"></img>
                  <span v-else>暂无</span>
                </div>
                <div v-if="val.title != '人脸照片'" class="grid-content bg-purple-light">{{ val.content ? val.content : '-'
                  }}</div>
              </el-col>
            </template>
          </el-row>
        </div>
      </div>
    </el-dialog>
    <!-- 用户详情 -->

    <!-- 添加新用户 -->
    <el-dialog title="添加新用户" :visible.sync="add_new_user" class="add_new_user" width="400px"
      :close-on-click-modal="false">
      <el-form :model="addForm" ref="addForm" :rules="rules" status-icon label-position="right" label-width="80px">
        <el-form-item label="真实姓名" prop="name">
          <el-input v-model="addForm.name" placeholder="请输入真实姓名(20个字符内)" autocomplete="off" :maxlength="parseInt(20)"
            clearable>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-radio v-model="addForm.sex" label="1">男</el-radio>
          <el-radio v-model="addForm.sex" label="2">女</el-radio>
        </el-form-item>
        <el-form-item label="组织架构" prop="org_id">
          <el-cascader placeholder="请选择组织架构" :options="orgData" :show-all-levels="false" :props="orgDataProps"
            v-model="AddFormOrgGroup"></el-cascader>
        </el-form-item>
        <el-form-item label="登录账号" prop="number">
          <el-input v-model="addForm.number" placeholder="请输入登录账号" autocomplete="off" :maxlength="parseInt(20)"
            clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="用户角色" prop="role_id">
          <el-checkbox-group v-model="addForm.role_id" @change="addFormRoleChange">
            <template v-for="item in roleData">
              <el-checkbox v-if="parseInt(item.id) > 0" :label="item.id" :key="item.id" border>{{ item.name
                }}</el-checkbox>
            </template>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addUser()">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="人脸照片" :visible.sync="dialogVisible" width="550px">
      <div style="padding-bottom: 30px;">
        <img :src="viewImgUrl" alt="" style="width: 100%;height: 100%;margin: auto;">
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { longTimeMessage } from './../../../tools/tool';

export default {
  data() {
    return {
      messageObj: {},
      rowLen: 0,
      loading: {
        status: false,
        txt: '获取数据...',
      },
      initFuncNum: 4,
      initFuncNumFinal: 0,
      roleData: [],
      roleParam: {
        type: 1,
      },
      userParam: {
        check_power: 1,
        status: [1, 3],
        role_id: 0,
        subject_id: 0,
        org_id: '',
        n_n_e: '',
        page: 1,
        pageSize: this.$store.getters.platformUserSize,
        data_type: 2,
      },
      keyword: '',
      subject_id: 0,
      roles_id: 0,
      org_id: '',
      total_number: 0,
      selected: [],
      orgParamData: [],
      orgData: [],
      orgDatas: [],
      orgParam: {
        data_type: 'manage_tree',
        status: [1, 2],
      },
      orgDataProps: {
        value: 'id',
        label: 'name',
      },
      selectedOrgOptions: [],
      addOrgOptions: [],
      subjectData: [],
      showTeacherAbout: false,
      pushIndexArr: { 1: '推首页', 0: '退首页' },
      statusArr: { 1: '启用', 3: '禁用' },
      teachSubject: '',
      addForm: {
        check_power: 1,
        name: '',
        sex: '1',
        number: '',
        role_id: [],
        org_id: ''
      },
      AddFormRoleGroup: [],
      AddFormOrgGroup: [],
      exprotParam: {},
      rules: {
        name: [
          { validator: this.validateContent, trigger: 'blur', required: true }
        ],
        number: [
          { validator: this.validateAccounts, trigger: 'blur', required: true },
          { pattern: this.rules.account.reg, message: this.rules.account.msg, trigger: 'blur' }
        ],
        role_id: [
          { type: 'array', validator: this.validateArray, trigger: 'change', required: true }
        ],
        org_id: [
          { validator: this.checkChange, trigger: 'change', required: true }
        ]

      },
      listData: [],
      isDetails: false,  /* 是否显示详情 */
      detailData: [], /* 详情列表 */
      detailParam: {
        id: '',
      },
      teachPostData: [],

      // 单级
      add_new_user: false,
      longSocket: null,
      viewImgUrl: null,
      dialogVisible: false
    };
  },
  created() {
    this.getRoleData()
    this.getOrgData()
    this.getParamOrgData()
    this.getSubjectData()
  },
  mounted() {
    this.websocketInit();
  },
  watch: {
    addPost: {
      handler(newVal, oldVal) {
        if (newVal === false) {
          this.resetAddForm();
        }
      },
      deep: true
    },
    selectedOrgOptions: {
      handler(newVal, oldVal) {
        console.log(newVal, oldVal)
        this.org_id = newVal[newVal.length - 1];
      },
      deep: true
    },
    userParamRole_id: {
      handler(newVal, oldVal) {
        if (parseInt(newVal) === this.$g.TEACHER_ROLE_ID) {
          this.showTeacherAbout = true;
        } else {
          this.showTeacherAbout = false;
        }
      },
      deep: true
    },
    initFuncNumFinal: {
      handler(newVal, oldVal) {
        if (parseInt(newVal) === this.initFuncNum) {
          this.getList();
        }
      },
      deep: true

    },
    AddFormOrgGroup: {
      handler(newVal, oldVal) {
        this.addForm.org_id = newVal[newVal.length - 1];
      },
      deep: true
    },
    add_new_user() {
      if (this.add_new_user === false) {
        this.AddFormOrgGroup = [];
        this.$refs.addForm.resetFields()
      }
    },
    changePageSize(newVal, oldVal) {
      this.userParam.pageSize = newVal;
    },
  },
  computed: {
    userParamRole_id() {
      return this.userParam.role_id;
    },
    changePageSize() {
      return this.$store.getters.platformUserSize;
    }
  },
  methods: {
    /**
     * websocket 连接，用户被修改后退出登录
     */
    websocketInit() {
      let webSocketURL = "ws://" + this.BASE_URL.split(":")[1] + ":7474";
      this.longSocket = new WebSocket(webSocketURL);

      this.longSocket.onopen = ((res) => { });
      this.longSocket.onmessage = (res => { });
      this.longSocket.onclose = (res => { })
    },
    openViewImg(row) {
      this.dialogVisible = true;
      this.viewImgUrl = this.BASE_URL + row.face_path;
      console.log('预览地址----', this.viewImgUrl)

    },
    checkSelectable(row) {
      if (row.check_power === true) {
        return true;
      }

      return false;
    },
    // 单级
    addUser() {
      let valid_res = true;
      this.$refs['addForm'].validate((valid) => {
        if (!valid) {
          valid_res = false
        }
      });
      if (!valid_res) return false;
      let success = (data => {
        this.add_new_user = false;
        this.$message.success(data.msg);
        this.$refs['addForm'].resetFields();
        this.getList();
      })
      this.$ajax.post('api/user/user', this.addForm, { func: { success: success } })

    },



    detailsVisible(row) {
      this.isDetails = true;
      let params = {
        id: row.id,
        level: 2
      }
      let success = (res => {
        console.log('详情----', res.data)
        let data = {
          data: res.data[0]
        }
        this.detailData = [];
        let rolesName = '';

        if (!is_empty(data.data.role)) {
          data.data.role.forEach(res => {
            if (rolesName.length == 0) {
              rolesName += res.name;
            } else {
              rolesName += ' & ' + res.name;
            }
          })
        }
        console.log('------aaaa', data.data.face_path)

        this.detailData.push({
          name: '基本信息',
          contents: [
            {
              title: '用户名',
              content: data.data.name
            },
            {
              title: '性别',
              content: data.data.sex === 1 ? '男' : '女'
            },
            {
              title: '角色',
              content: rolesName
            },
            {
              title: '登录帐号',
              content: data.data.number + ' <span>' + this.getMailPhone(data.data.email, data.data.telphone) + '</span>'
            },
            {
              title: '注册时间',
              content: data.data.create_time
            },
            {
              title: '人脸照片',
              content: data.data.face_path
              // content: "http://172.16.93.3:8082/static/image/management/affairs.svg"
            }
          ]
        })

        if (data.data.is_teacher === 1) {
          let teacherInfo = [];
          this.teachPostData = [];

          if (data.data.teacher_org) {
            data.data.teacher_org.forEach(item => {
              let jobName = '-';
              this.getClassJob(item.class_id, item.teacher_job_id).then(res => {
                jobName = res;

                teacherInfo.push({
                  title: '任教班级',
                  content: this.getTeacherInfo(item.study_org_id, item.grade_id, item.class_id)
                })
                teacherInfo.push({
                  title: '任教学科',
                  content: this.subjectData.filter(val => val.id !== 0 && val.id == data.data.subject_id)[0] ? this.subjectData.filter(val => val.id !== 0 && val.id == data.data.subject_id)[0].name : '-'
                })
                teacherInfo.push({
                  title: '班级岗位',
                  content: jobName
                })
              }).then(err => {
                if (err) {
                  teacherInfo.push({
                    title: '任教班级',
                    content: '-'
                  })
                  teacherInfo.push({
                    title: '任教学科',
                    content: '-'
                  })
                  teacherInfo.push({
                    title: '班级岗位',
                    content: '-'
                  })
                }
              })
            })
          }

          this.detailData.push({
            name: '角色信息（教师）',
            contents: teacherInfo
          })
        }

        if (data.data.is_parent === 1) {
          let childrenInfo = [];

          if (!is_empty(data.data.children_info)) {
            data.data.children_info.forEach(item => {
              childrenInfo.push({
                title: '子女帐号',
                content: item.number
              })
              childrenInfo.push({
                title: '子女姓名',
                content: item.name
              })
              childrenInfo.push({
                title: '子女班级',
                content: item.class_name
              })
            })
          }

          this.detailData.push({
            name: '角色信息（家长）',
            contents: childrenInfo
          })
        }

        this.detailData.push({
          name: '联系信息',
          contents: [
            {
              title: '手机号码',
              content: data.data.telphone
            },
            {
              title: '用户邮箱',
              content: data.data.email
            }
          ]
        })

        this.isDetails = true;
      });
      let fail = (data => {
        this.$message.error(data.msg)
      })
      // ai分析后接口api/user/user_info改api/user/user
      this.$ajax.get('api/user/user', { params: params, func: { success: success, fail: fail } })
    },
    getMailPhone(mail, phone) {
      if (mail === '' && phone === '') {
        return '';
      }
      if (mail !== '' && phone !== '') {
        return '已绑定手机 & 邮箱'
      }
      if (mail === '') {
        return '已绑定手机'
      } else {
        return '已绑定邮箱'
      }
    },
    async getClassJob(classId, jobId) {
      let params = {
        class_id: classId,
      }
      let name = '-';

      const success = res => {
        this.teachPostData.push({
          id: classId,
          dataList: res.data.teacher_job
        })

        if (!is_empty(this.teachPostData)) {
          this.teachPostData.forEach(item => {
            if (item.id == classId) {
              if (!is_empty(item.dataList)) {
                item.dataList.forEach(res => {
                  if (res.job_id == jobId) {
                    name = res.job_name;
                  }
                })
              }
            }
          })
        }
      }
      await this.$ajax.get('api/user/class_job_data', { params: params, func: { success: success } })

      return name;
    },
    getTeacherInfo(orgId, gradeId, classId) {
      let item = this.orgData[0].children;
      for (let i = 0; i < item.length; i++) {
        if (item[i].id == orgId) {
          let res = item[i].children;
          for (let j = 0; j < res.length; j++) {
            if (res[j].id == gradeId) {
              let res2 = res[j].children;
              for (let k = 0; k < res2.length; k++) {
                if (res2[k].id == classId) {
                  return res[j].name + res2[k].name
                }
              }
            }
          }
        }
      }

      return '-'
    },
    searchFunc() {
      this.userParam.n_n_e = this.keyword;
      this.userParam.org_id = this.org_id;
      this.userParam.role_id = this.roles_id;
      this.userParam.subject_id = this.subject_id;
      this.userParam.page = 1;
      this.getList();
    },
    reset() {
      this.keyword = '';
      this.subject_id = 0;
      this.org_id = '';
      this.roles_id = 0;
      this.userParam = {
        check_power: 1,
        status: [1, 3],
        role_id: 0,
        subject_id: 0,
        org_id: '',
        n_n_e: '',
        page: 1,
        pageSize: 10,
        data_type: 2,
      }
      this.$store.commit('SET_PLATFORMUSERSIZE', 10);
      this.selectedOrgOptions = [];
      this.getList();
      this.getOrgData();
    },
    eidtUser(row) {
      this.$router.push('/user/user/edit-platform-user/' + row.id)
    },
    getSubjectData() {
      // 重写成功回调
      let success = (data => {
        this.subjectData = [];
        this.subjectData = data.data;
        this.subjectData.unshift({ id: 0, name: '全部' });
        this.initFuncNumFinal++;

      });
      this.$ajax.get('api/cate/simple_subject', { params: {}, func: { success: success } })
    },
    getOrgData() {                         // 获取组织架构
      if (this.$store.state.checkLevel) {
        this.orgParam.direction = 'down'
        this.orgParam.data_type = 'manage_tree'
        this.orgParam.pid = 1
      }
      // 重写成功回调
      let success = (data => {
        this.orgData = data.data;
        this.orgDatas = this.getTreeData(data.data[0].children, 4);
        // console.log(JSON.parse(JSON.stringify(data.data)), 10000)
        this.selectedOrgOptions.push(this.orgData[0].id);
        this.$forceUpdate();//强制渲染
        this.initFuncNumFinal++;
      });
      if (this.$store.state.checkLevel) {
        this.$ajax.get('api/newlevel/platform_org', { params: this.orgParam, func: { success: success } })
      } else {
        this.$ajax.get('api/org/org', { params: this.orgParam, func: { success: success } })
      }
    },
    // 递归遍历将多层嵌套数组里最里的空children数组的值改为undefined
    getTreeData(data, level) {
      // 循环遍历json数据
      for (var i = 0; i < data.length; i++) {
        if (data[i].children.length < 1) {
          // children若为空数组，则将children设为undefined
          if (data[i].level == level) data[i].children = undefined;
        } else {
          // children若不为空数组，则继续 递归调用 本方法
          this.getTreeData(data[i].children, level);
        }
      }
      return data;
    },
    getParamOrgData() {
      // 重写成功回调
      if (this.$store.state.checkLevel) {
        this.orgParam.direction = 'down'
        this.orgParam.data_type = 'manage_tree'
        this.orgParam.pid = 1
      }
      let success = (data => {
        this.orgParamData = data.data;
        this.selectedOrgOptions.push(this.orgParamData[0].id);
        this.$forceUpdate();//强制渲染
        this.initFuncNumFinal++;
      });
      var params = deep_clone(this.orgParam);
      params.diff_platform = 1;
      if (this.$store.state.checkLevel) {
        this.$ajax.get('api/newlevel/platform_org', { params, func: { success: success } })
      } else {
        this.$ajax.get('api/org/org', { params, func: { success: success } })
      }
    },
    getRoleData() {
      this.loading.status = true;
      // 重写成功回调
      let success = (data => {
        this.roleData = [];
        this.roleData = deep_clone(data.data);
        this.roleData.unshift({ id: 0, name: '全部角色', data: [] });
        this.userParam.role_id = this.roleData[0].id;

        this.initFuncNumFinal++;
      });
      let fail = (data => {
        this.loading.status = false
        this.$message.error(data.msg)
      })
      this.$ajax.get('api/user/user_allow_control', { params: this.roleParam, func: { success: success, fail: fail } })

    },
    getList() {
      this.loading.status = true;
      // 重写成功回调
      let success = (data => {
        this.loading.status = false
        console.log(data.data.data)
        this.listData = data.data.data;
        this.total_number = data.data.data_sum;
        this.$forceUpdate();//强制渲染
      });
      let fail = (data => {
        this.loading.status = false;
        this.$message.error(data.msg)
      })
      let params = {
        ...this.userParam,
        ...{
          size: this.userParam.pageSize,
          pageSize: undefined
        }
      }

      this.$ajax.get('api/user/user', { params, func: { success: success } })
    },
    pushTeacherIndex_confirm(obj, status) {
      let yes = (data => {
        this.pushTeacherIndex(obj.id, status);
      })
      let cancel = (data => { })
      this.e_confirm({ yes: yes, cancel: cancel, txt: '确定将 ' + obj.name + ' ' + this.pushIndexArr[parseInt(status)] + ' 吗？' });

    },
    pushTeacherIndex(id, status) {
      let success = (data => {
        this.$message.success(data.msg)
        this.getList();
      });
      this.$ajax.put('api/user/teacher_push_index', { id: id, status: status }, { func: { success: success } })
    },
    deleteUser_confirm(obj) {
      let yes = (data => {
        this.rowLen = 1;
        this.changeUser(obj.id, 0);
      })
      let cancel = (data => { })
      this.e_confirm({ yes: yes, cancel: cancel, txt: '确定将 ' + obj.name + ' 删除吗？' });

    },
    deleteMuiltUser_confirm() {
      if (this.selected.length === 0) {
        this.$message.warning("请选择要删除的项");
        return false;
      }
      let yes = (data => {
        this.rowLen = this.selected.length;
        this.deleteMuiltUser();
      })
      let cancel = (data => { })
      this.e_confirm({ yes: yes, cancel: cancel, txt: '确定要删除选中的项吗？' });

    },
    deleteMuiltUser() {
      let ids = [];
      for (let i = this.selected.length - 1; i >= 0; i--) {
        ids.push(this.selected[i].id)
      }
      this.changeUser(ids, 0);
    },
    changeUser_confirm(obj, status) {
      let yes = (data => {
        this.changeUser(obj.id, status);
      })
      let cancel = (data => { })
      this.e_confirm({ yes: yes, cancel: cancel, txt: '确定将 ' + obj.name + ' 设置为 ' + this.statusArr[parseInt(status)] + ' 吗？' });

    },
    changeUser(id, status) {
      let success = (data => {
        this.$message.success(data.msg);

        if (this.listData.length - this.rowLen === 0) {
          if (this.userParam.page > 1) {
            this.userParam.page--;
          } else {
            this.userParam.page = 1;
          }
        }

        if (status == 3 || status == 0) { // 禁用、删除
          let params = {
            type: "delete_login",
            token: sessionStorage.getItem('token'),
            terminal_type: 1,
            delete_userid: id,
          }

          this.longSocket.send(JSON.stringify(params));
        }

        this.getList();
      });
      let fail = (res => {
        longTimeMessage(this, res, 15000);

        this.getList();
      })

      this.$ajax.put('api/user/change_user', { id: id, status: status }, { func: { success: success, fail: fail } })
    },
    // 批量导入
    batchImport() {
      this.$router.push("/user/user/batch-import")
    },
    // 验证
    validateContent(rule, value, callback) {
      if (value === '') {
        return callback(new Error('请输入真实姓名'));
      } else if (!validateName(value)) {
        return callback(new Error('不能输入空格符号'));
      } else {
        callback()
      }
    },
    validateAccounts(rule, value, callback) {
      if (value === '') {
        return callback(new Error('请输入登录账号'));
      } else if (!validateName(value)) {
        return callback(new Error('不能输入空格符号'));
      } else {
        callback()
      }
    },
    checkChange(rule, value, callback) {
      if (!isEmpty(value)) {
        return callback(new Error('请选择组织架构'));
      } else {
        callback()
      }
    },
    validateArray(rule, value, callback) {
      if (value.length <= 0) {
        return callback(new Error('请至少选择一个用户角色'));
      } else {
        callback()
      }
    },
    //选中
    tableSelectionChange(val) {
      this.selected = val;
    },
    handleSizeChange(val) {
      this.userParam.page = 1;
      this.userParam.pageSize = val;
      this.$store.commit('SET_PLATFORMUSERSIZE', val);
      this.getList();
    },
    handleCurrentChange(val) {
      this.userParam.page = val;
      this.getList();
    },
    exportUser() {
      if (this.listData.length === 0) {
        this.$message.warning("导出的数据为空！")
        return false;
      }

      this.export_excel('api/user/user_export_excel', this.userParam, '平台用户');
    },
    addFormRoleChange(val) {
      let curRoleId = parseInt(val[val.length - 1]);
      if (this.$g.STUDENT_ROLE_ID === curRoleId || curRoleId >= 7) {
        this.addForm.role_id = [curRoleId];
      } else {
        for (let i = val.length - 1; i >= 0; i--) {
          let roleIdInx = parseInt(val[i]);
          if (this.$g.STUDENT_ROLE_ID === roleIdInx || roleIdInx >= 7) {
            this.addForm.role_id.splice(i, 1);
          }
        }
      }
    },
    jumpEdit(id) {
      this.$router.push('/user/user/edit-platform-user/' + id);
    },
    /**
     * 添加用户
     * 2019-5-5 按产品要求，单级、多级合并，按照多级的页面来做，单级、多级用同一接口。
     */
    jumpAdd() {
      // if (this.user_multistage === true) {
      this.$router.push('/user/user/add-platform-user/');
      // } else {
      //     this.add_new_user = true;
      // }
    },
  },
  destroyed(to, from, next) {
    this.$message.closeAll();
  },
};
</script>
<style lang="scss">
.zh-platform-user {
  .details-content {
    .card {
      p:first-child {
        border-left: 5px solid #4CC3C3;
        padding-left: 7px;
        text-align: left;
      }

      .el-row {
        padding-bottom: 10px;

        >div:first-child {
          text-align: right;
        }

        >div:last-child {
          padding-left: 25px;
          text-align: left;
        }
      }
    }

    .card:last-child {
      padding-bottom: 40px;
    }

    .card:not(:first-child):not(:last-child) {
      .el-row:nth-child(3n):not(:last-child) {
        border-bottom: 1px dotted #ccc;
        margin-bottom: 20px;
      }
    }
  }

  .el-table__body-wrapper table tbody {
    td:nth-child(11) {
      padding: 0;
    }
  }

  .zh-table-contents {
    .el-button+.el-button {
      margin-left: 2px;
    }

    .home-color {
      color: #409EFF;
    }
  }

  .isDetails {
    .el-dialog__body {
      padding: 30px 30px;
    }
  }

  .el-checkbox.is-bordered+.el-checkbox.is-bordered {
    margin-right: 10px;
    margin-left: 0;
  }

  .el-checkbox.is-bordered.el-checkbox--small {
    margin-right: 10px;
  }

  .bg-purple-light span {
    padding-left: 30px;
    color: #aaa;
  }
}
</style>
